package com.tys.algorithm.advanced.test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class Tmp {


//    public static class IdShengAgeJiangOrder implements Comparator<Student> {
//        public int compare(Student o1, Student o2){
////        if(o1.age < o2.age){
////            return -1;
////        }else if(o1.age > o2.age){
////            return 1;
////        }else{
////            return 0;
////        }
//            //上面可以用下面一行代替
//            return o1.age - o2.age;
//        }
//    }


    /**
     * @param beginTime 执行定时任务   24小时制时间 例: 08:00:00  20:00:00
     * @throws ParseException
     */
    public static void timing(String beginTime) throws ParseException {

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentDay = format.format(new Date());
        Date currentDay1 = format.parse(beginTime);
        System.out.println(currentDay);
        System.out.println(format.format(currentDay1));


        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                // TODO 执行任务
                System.out.println("执行任务");
            }
        };

        Timer timer = new Timer(true);
        timer.schedule(task, format.parse(beginTime));
    }

    public static boolean isTimeout(String endTime) {

        //获取当前时间
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String curTime = df.format(System.currentTimeMillis());
        return curTime.compareTo(endTime) >= 0;
    }

    public static void main(String[] args) {


        //        String endTime = "2023-02-22 18:44:55";
//        System.out.println(isTimeout(endTime));

//        try {
//            // 每天8点执行定时任务
//            System.out.println("begin");
////            String beginTime = "2023-02-21 17:03:00";
//            String beginTime = "17:03:00";
//            timing(beginTime);
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }

//        TimerTask timerTask = new TimerTask() {
//            @Override
//            public void run() {
//                System.out.println("hell world");
//            }
//        };
//        Timer timer = new Timer();
//        timer.schedule(timerTask, 10, 3000);

//        System.out.println("end");

    }
}
